//
//  ImportWalletVC.m
//  ShandsMod
//
//  Created by zh s on 2023/3/21.
//  Copyright © 2023 zh_s. All rights reserved.
//

#import "ImportWalletVC.h"

#import "ImportWalletInputCell.h"
#import "ImportWalletInfoCell.h"
#import "ImportWalletBtnCell.h"

#import "HelpWordsVC.h"

@interface ImportWalletVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *mainTableView;
@property (nonatomic, strong) NSArray *dataArr;

@end

@implementation ImportWalletVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle = @"导入钱包";
    UIView *headerV = [[UIView alloc] init];
    [self.view addSubview:headerV];
    headerV.backgroundColor = UIColor.whiteColor;
    [headerV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(self.nav.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 42));
    }];
    
    NSArray *titleArr = @[@"私钥导入",@"助记词"];
    for (int i = 0; i < 2; i ++) {
        UIButton *change = [BaseViewFactory buttonWithFrame:CGRectZero font:FONT_NAME(FONT_Regular, 16) title:titleArr[i] titleColor:TEXT_COLOR_51 backColor:UIColor.clearColor];
        [headerV addSubview:change];
        [change mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(SCREEN_WIDTH/2 *i);
            make.top.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH/2, 42));
        }];
        change.tag = 10 + i;
        [change addTarget:self action:@selector(changeClick:) forControlEvents:UIControlEventTouchUpInside];

        if (i == 0) {
            change.titleLabel.font = FONT_NAME(FONT_Semibold, 16);
            
            UIView *lineView = [[UIView alloc] init];
            [headerV addSubview:lineView];
            lineView.backgroundColor = MAIN_ACTIVE_COLOR;
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(headerV.mas_bottom).mas_offset(0);
                make.centerX.mas_equalTo(change.mas_centerX);
                make.height.mas_equalTo(2.5);
                make.width.mas_equalTo(11);
            }];
            GWRadius(lineView, 1);
            lineView.tag = 20 + i;

        }else {
            
        }
    }
    
    [self data_init];
    [self UI_init];
    
}

#pragma mark ----- UI_init
- (void)UI_init {
    [self.view addSubview:self.mainTableView];
}
#pragma mark ----- data_init
- (void)data_init {
    _dataArr = @[];
}
#pragma mark ----- tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        ImportWalletInputCell *inputCell = [tableView dequeueReusableCellWithIdentifier:@"inputCell" forIndexPath:indexPath];
        return inputCell;
    }else if (indexPath.section == 1) {
        ImportWalletInfoCell *infoCell = [tableView dequeueReusableCellWithIdentifier:@"infoCell" forIndexPath:indexPath];
        return infoCell;
    }
    ImportWalletBtnCell *cell = [tableView dequeueReusableCellWithIdentifier:@"btnCell" forIndexPath:indexPath];
    cell.ysxyBlock = ^{
        [self privacyBtnClick];
    };

    [cell.createBtn addTarget:self action:@selector(createWalletClick) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 155;
    }else if (indexPath.section == 1) {
        return 254;
    }
    return 75;
    
}

#pragma mark ----- 点击事件
- (void)changeClick:(UIButton *)sender {
    UIButton *importBtn = [self.view viewWithTag:10];
    UIButton *helpBtn = [self.view viewWithTag:11];
    UIView *lineV = [self.view viewWithTag:20];
    if (sender.tag == 10) {
        importBtn.titleLabel.font = FONT_NAME(FONT_Semibold, 16);
        
        [lineV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(sender.mas_bottom).mas_offset(0);
            make.centerX.mas_equalTo(sender.mas_centerX);
            make.height.mas_equalTo(2.5);
            make.width.mas_equalTo(11);
        }];
//        helpBtn.titleLabel.font = FONT_NAME(FONT_Regular, 16);
    }else {
//        importBtn.titleLabel.font = FONT_NAME(FONT_Regular, 16);
//        helpBtn.titleLabel.font = FONT_NAME(FONT_Semibold, 16);
        HelpWordsVC *vc = [[HelpWordsVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
  
    
}

-(void)privacyBtnClick {
    
//http://sxe.shands.cn/ysbh.html
    CustomWebviewVC *vc = [[CustomWebviewVC alloc] init];
    vc.navTitleStr = @"使用者协议";
    vc.isShowNav = YES;
    vc.urlStr = @"http://sxe.shands.cn/ysbh.html";
    [self.navigationController pushViewController:vc animated:YES];

}

- (void)createWalletClick {

}



#pragma mark ----- 懒加载
- (UITableView *)mainTableView {
    if (!_mainTableView) {
        _mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NAV_HEIGHT +42, SCREEN_WIDTH, SCREEN_HEIGHT -NAV_HEIGHT -42) style:UITableViewStyleGrouped];
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        _mainTableView.showsVerticalScrollIndicator = NO;
        _mainTableView.estimatedRowHeight = 44;//推测高度，必须有，可以随便写多少
        _mainTableView.rowHeight =UITableViewAutomaticDimension;//iOS8之后默认就是这个值，可以省略
        _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        _mainTableView.backgroundColor = BASE_BACKCOLOR;
        [_mainTableView registerClass:[ImportWalletBtnCell class] forCellReuseIdentifier:@"btnCell"];
        [_mainTableView registerClass:[ImportWalletInputCell class] forCellReuseIdentifier:@"inputCell"];
        [_mainTableView registerClass:[ImportWalletInfoCell class] forCellReuseIdentifier:@"infoCell"];
    }
    return _mainTableView;
}

@end
